package com.ftf.tp.blog.infrastructure.repository;

import com.ftf.tp.blog.domain.article.dos.ArticleCommentDO;
import com.ftf.tp.blog.domain.article.repository.CommentRepository;
import com.ftf.tp.blog.infrastructure.converter.CommentConverter;
import com.ftf.tp.blog.infrastructure.mapper.ArticleCommentMapper;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author tanghao
 * @date 2022/7/29
 */
@Repository
public class CommentRepositoryImpl implements CommentRepository {

    @Resource
    private ArticleCommentMapper articleCommentMapper;

    /**
     * 新增评论
     *
     * @param articleCommentDO 评论领域实体
     */
    @Override
    public void saveComment(ArticleCommentDO articleCommentDO) {
        articleCommentMapper.insert(CommentConverter.INSTANCE.convert(articleCommentDO));
    }

    /**
     * 根据id获取评论实体
     *
     * @param commentId 评论id
     * @return 评论实体
     */
    @Override
    public ArticleCommentDO byId(Long commentId) {
        return CommentConverter.INSTANCE.convert(articleCommentMapper.selectById(commentId));
    }


    @Override
    public int getRankById(Long commentId) {
        return articleCommentMapper.getRankById(commentId);
    }

    /**
     * 根据id删除评论
     *
     * @param commentId 评论id
     */
    @Override
    public void deleteById(Long commentId) {
        articleCommentMapper.deleteById(commentId);
    }
}
